package com.tianye.lc.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tianye.lc.R;
import com.tianye.lc.activity.BaseActivity;
import com.tianye.lc.activity.BreedActivity;
import com.tianye.lc.activity.YuhuaguRoseListActivity;

import java.util.List;

/**
 * Created by yangyazhou on 2016/12/20.
 */

public class MainRecyclerAdapter extends RecyclerView.Adapter<MainRecyclerAdapter.ListViewHolder> {
    private BaseActivity mActivity;
    private List<String> mData;

    public MainRecyclerAdapter(BaseActivity activity) {
        mActivity = activity;
    }

    public void setData(List<String> data) {
        mData = data;
        notifyDataSetChanged();
    }


    @Override
    public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ListViewHolder(mActivity.getLayoutInflater().inflate(R.layout.list_item_main, parent, false));
    }

    @Override
    public void onBindViewHolder(ListViewHolder holder, int position) {
        holder.name.setText(mData.get(position));
    }

    @Override
    public int getItemCount() {
        if (null == mData) {
            return 0;
        }
        return mData.size();
    }


    public class ListViewHolder extends RecyclerView.ViewHolder {
        private TextView name;

        public ListViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (getAdapterPosition() == 0) {
                        mActivity.startActivity(new Intent(mActivity, BreedActivity.class));
                    }else if (getAdapterPosition() == 1) {
                        mActivity.startActivity(new Intent(mActivity, YuhuaguRoseListActivity.class));
                    }
                }
            });
        }
    }

}
